#include "FilterFactory.h"
#include "Filter.h"
#include "bgremove.h"
#include "contrast.h"
#include "highpass.h"
#include "simplehighpass.h"
#include "scaler.h"
#include "smooth.h"
#include "thresh.h"

using namespace std;

FilterFactory::FilterFactory(void)
{
	filter_map.insert(make_pair("bgremove",BGREMOVE_FILTER));
	filter_map.insert(make_pair("contrast",CONTRAST_FILTER));
	filter_map.insert(make_pair("highpass",HIGHPASS_FILTER));
	filter_map.insert(make_pair("smooth",SMOOTH_FILTER));
	filter_map.insert(make_pair("thresh",THRESH_FILTER));
	filter_map.insert(make_pair("simple_highpass",SIM_HIGHPASS_FILTER));
	filter_map.insert(make_pair("scaler",SCALER_FILTER));

}

Filter* FilterFactory::get_filter(int filter_index)
{
	size_t i;
	for(i=0;i<filter_chain.size();i++){
		if(filter_chain[i]->get_filter_index()== filter_index){
			return filter_chain[i];
		}
	}
	return NULL;

}

Filter* FilterFactory::get_filter(string name)
{
	int inx = filter_map[name];
	return get_filter(inx);

}

void FilterFactory::load_full_default_filter(void)
{
	reset();

	Filter *bgremove_f = new bgremove();
	Filter *contrast_f = new contrast();
	Filter *highpass_f = new highpass();
	Filter *simple_highpass_f = new simplehighpass();
	Filter *smooth_f = new smooth();
	Filter *scaler_f = new scaler();
	Filter *thresh_f = new thresh();

	filter_chain.push_back(bgremove_f);
	//filter_chain.push_back(contrast_f);
	filter_chain.push_back(simple_highpass_f);
	filter_chain.push_back(scaler_f);
	//filter_chain.push_back(smooth_f);
	filter_chain.push_back(thresh_f);

}

bool FilterFactory::load_filter_chain_from_file(string name)
{
	reset();
	//TO DO load old configuration
	return false;
}

void FilterFactory::save_filter_chain_to_file(string name)
{
	//TO DO save configuration

}

void FilterFactory::reset(void)
{
	size_t i;
	for(i=0;i<filter_chain.size();i++){
		delete filter_chain[i];
	}
	filter_chain.clear();
}

FilterFactory::~FilterFactory()
{
}